
<?php
session_start();
ob_start();
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../css/css.css" rel="stylesheet" type="text/css"/>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <title>Hoai Tam</title>
    </head>
    <body>
        <?php
        require_once './model/db.php';
        require_once './model/keywords.php';
        require_once './model/Works.php';
        $works = new work();
        ?>
        <?php
        $keywords = new work();
        $list = $keywords->works1();
        ?>

        <div id="hinh"></div>
        <div id="page">
            <div id="menu">
                <ul>
                    <li><a href="index.php"><strong>HOME</strong></a></li>
                    <li><a href="#"><strong>CONTENT TYPE</strong></a>

                    </li>
                    <li><a href="#"><strong>FORUM</strong></a> </li>
                    <li><a href="#"><strong>CONTACT</strong></a></li>
                </ul>
            </div>
            <div id="header">


            </div>

            <?php
            if (isset($_GET["logout"]) && $_GET["logout"] == true) {
                unset($_SESSION["id"]);
                header("location:login.php");
            }
            ?>
            <div class="ajax_show"></div>
            <from method='GET'>  

                <?php if (isset($_SESSION['id'])): ?>
                    <a href="index.php?logout=true"><h3>Logout</h3></a>
                <?php else: ?>
                    <a href="login.php"><h3>Login</h3></a>
                <?php endif; ?> 



                <a href='index.php?page=1'> First</a>
                <?php if (isset($_GET['page'])) { ?>
                    <a href='index.php?page=<?php echo $_GET['page'] - 1 ?>'> Prew </a>
                <?php } ?>
                <?php
                $page = 5;

                if ((isset($_GET['page'])) && ($_GET['page'] <= 3)) {
                    for ($i = 1; $i <= $page; $i++) {
                        ?> 
                        <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                        <?php
                    }
                } else if ((isset($_GET['page'])) && ($_GET['page'] >= 17)) {
                    for ($i = 15; $i <= 19; $i++) {
                        ?> 
                        <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                        <?php
                    }
                } else if (isset($_GET['page'])) {
                    for ($i = ($_GET['page'] - 2); $i <= ($_GET['page'] + 2); $i++) {
                        ?>
                        <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                        <?php
                    }
                } else {
                    ?>
                    <a href='index.php'> Prew </a>
                    <?php for ($i = 1; $i <= 5; $i++) { ?>
                        <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                    <?php } ?>
                    <a href='index.php?page=2'> Next </a>
                <?php } ?>
                <?php if (isset($_GET['page'])) { ?>
                    <a href='index.php?page=<?php echo $_GET['page'] + 1 ?>'> Next </a>
                <?php } ?>
                <a href='index.php?page=19'>Last</a>
                </table>


            </from>


            <?php
            $page = 1;
            if (isset($_GET['page']))
                $page = $_GET['page'];
            $from = PER_PAGE * ($page - 1);
            $to = PER_PAGE;
            $query = "SELECT * FROM works LIMIT $from ,$to";
            $list = $keywords->select($query);
            ?>
        </from>
        <table border="1px">
            <tr>
                <td>ID</td>
                <td>Name</td>
                <td>Posted</td>
                <td>Location</td>
                <td>Images</td>
                <td>Operation</td>

            </tr>
            <?php foreach ($list as $lists) : ?> 
                <tr>
                    <td><?php echo $lists['id']; ?></td>
                    <td><?php echo $lists['name']; ?></td>
                    <td><?php echo $lists['posted']; ?></td>
                    <td><?php echo $lists['location']; ?></td>
                    <td> <img src="<?php echo $lists['image']; ?>"width="100px"></td>
                    <?php if (isset($_SESSION['id']) && $_SESSION['id'] == 0) : ?>

                        <td><img src="public/images/aa.png" width="15px" height="15px"><a href="edit.php?id=<?php echo $lists['id'] ?>">Edit</a><br>
                            <a href="#" class="ajax_view" id_keyword="<?php echo $lists["name"]; ?>">  View  </a><br>
                            <img src="public/images/Fast Delete Icon Base-1394585131.png" width="15px" height="15px"><a href="submit.php">Delete</a></td>

                    <?php else: ?>
                        <td>
                            
                            <a href="#" class="ajax_view" id_keyword="<?php echo $lists["name"]; ?>">  view  </a><br>
                            
                        </td>
                    <?php endif; ?>
                </tr>
            <?php endforeach; ?>
        </table>
    </div>
    <div class="cuoi">Hoài Tâm C12TDT</div>

    <script type="text/javascript">
                        $(document).ready(function(){
                            $(".ajax_view").click(function(){      
                                id_keyword = $(this).attr('id_keyword');
                                url = 'ajax.php?id_keyword='+id_keyword;
                                $.ajax({
                                    url: url,                                    
                                    }).done(function(data) {
                                        $('.ajax_show').html(data);
                                    });
                            });
                        });
        </script>
</body>
</html>
